//
//  TableViewController.m
//  xib-work4
//
//  Created by 金隆 on 2017/4/11.
//  Copyright © 2017年 金隆. All rights reserved.
//

#import "TableViewController.h"
#import "TableTableViewCell.h"
#import "OneViewController.h"
#import "TwoViewController.h"
#import "ThreeViewController.h"
#import "FourViewController.h"

@interface TableViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSArray *arr;
@property (strong, nonatomic) OneViewController *one;
@end

static NSString *tabCell = @"tabCell";

@implementation TableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"iosDemo";
    self.arr = @[@"1",@"2",@"tableView练习",@"4",@"5",@"6",@"7",@"8",@"9",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"TableTableViewCell" bundle:nil] forCellReuseIdentifier:tabCell];
    _one = [[OneViewController alloc]init];
    NSLog(@"第一个指针%p",_one);
    _one.str = @"++++";
    // Do any additional setup after loading the view from its nib.
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _arr.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
    if(indexPath.row == 0){
        return 60;
    }else if (indexPath.row == 1) {
        return 70;
    }else{
        return 60;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TableTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tabCell forIndexPath:indexPath];
    NSString *str = _arr[indexPath.row];
    if (indexPath.row == 0) {
        cell.contentLab.text = @"消息通知";
    }
    if (indexPath.row == 4) {
        cell.contentLab.text = @"第五行";
    }else{
        cell.contentLab.text = str;
    }
    cell.img.image = [UIImage imageNamed:@"ima1.png"];

    return cell;
}

    //点击事件的回调方法区域
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        OneViewController *one = [[OneViewController alloc]init];
        NSLog(@"打印值%@",one.str);
        NSLog(@"全局%@",_one.str);
        _one.str = @"";
        one.str = @"123";
        NSLog(@"第二次打印%@",one.str);

//        NSLog(@"第二个指针%p",one);
//        one.str = @"123";
        [self.navigationController pushViewController:one animated:YES];
    }
    if (indexPath.row == 1) {
        TwoViewController *two =[[TwoViewController alloc]init];
        [self presentViewController:two animated:YES completion:nil];
    }
    if (indexPath.row == 2) {
        ThreeViewController *three = [[ThreeViewController alloc]init];
        [self.navigationController pushViewController:three animated:YES];
    }
    if (indexPath.row ==  8) {
//        TableTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tabCell forIndexPath:[NSIndexPath indexPathForRow:5 inSection:0]];
//        cell.contentLab.text = @"改变了第五行的值";
        TableTableViewCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:5 inSection:0]];
        cell.contentLab.text = @"改变了第五行的值";
    }
    if (indexPath.row == 3){
        FourViewController *four = [[FourViewController alloc]init];
        [self.navigationController pushViewController:four animated:YES];
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
